﻿using Authentication.Core.Configuration;
using Authentication.Model.Model;
using Common.Data.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Authentication.Core.Data.DBConfig
{
    public class GroupRuleConfiguration : DBConfig<ApplicationGroupRule>
    {
        public GroupRuleConfiguration()
            : base(SystemConfiguration.Schema, SystemConfiguration.NamingType, SystemConfiguration.TABLE_PREFIX)
        {
            HasKey(x => new { x.ApplicationKey, x.GroupId, x.ObjectId, x.RuleId, x.DepartmentId });
            Property(c => c.ApplicationKey).IsRequired().HasMaxLength(36);
            Property(c => c.GroupId).IsRequired().HasMaxLength(20);
            Property(c => c.ObjectId).IsRequired().HasMaxLength(20);
            Property(c => c.RuleId).IsRequired();
            Property(c => c.Active).HasMaxLength(1);



            //relationship  
            HasRequired(ad => ad.Object).WithMany(s => s.GroupRules).HasForeignKey(t => new { t.ApplicationKey, t.ObjectId });
        }
    }
}
